<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="*|/"><xsl:apply-templates/></xsl:template>

<xsl:template match="text()|@*"><xsl:value-of select="."/></xsl:template>

<xsl:template match='nbsp' name='nbsp'>
<xsl:text disable-output-escaping='yes'>&amp;nbsp;</xsl:text>
</xsl:template>

<xsl:template name="subMessages">
<xsl:param name="messageID"/>
<xsl:param name="counter"/>
	<xsl:for-each select="/forum/smessage">
	<xsl:choose>
		<xsl:when test='@ref=$messageID'>
	<tr>
	<xsl:choose>
		<xsl:when test='@ngId'>
			<td class="body9"><img height="1px" width="{$counter}" src="/imgs/white_sp.gif"/><img src="/imgs/replyarrow.gif"/>
			<xsl:value-of select="@ngFrom"/>
			</td>
		</xsl:when>
		<xsl:otherwise>
			<td class="body9"><a style="color:#006699;" href="/profileShow.aspx?userGuid={@userid}"><xsl:value-of select="@nick"/></a></td>
		</xsl:otherwise>
	</xsl:choose>
	<td>
	<a href="/forumReadMessage.aspx?forumid={/forum/@ID}&amp;msgid={@ID}">
	<img border="0" src="/imgs/message.gif"/>
	</a>
	&#160;
	<xsl:choose>
		<xsl:when test='@ngId'>
			<a href="/forumReadMessage.aspx?forumid={/forum/@ID}&amp;msgid={@ID}">
			<xsl:value-of select="@ngSubj"/>
			</a>
		</xsl:when>
		<xsl:otherwise>
			<xsl:choose>
				<xsl:when test='@textLen&gt;@maxLen'>
					<a href="/forumReadMessage.aspx?forumid={/forum/@ID}&amp;msgid={@ID}">
				  <xsl:call-template name="lf2br">
					<xsl:with-param name="text" select="@text"/>
				  </xsl:call-template>
					</a>
				</xsl:when>
				<xsl:otherwise>
				  <xsl:call-template name="lf2br">
					<xsl:with-param name="text" select="@text"/>
				  </xsl:call-template>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:otherwise>
	</xsl:choose>
	</td>
	<td class="body9">
		<xsl:call-template name="sp2br">
		<xsl:with-param name="text" select="@time"/>
		</xsl:call-template>
	</td>
	</tr>
			<xsl:call-template name="subMessages">
			<xsl:with-param name="messageID" select="@ID"/>
			<xsl:with-param name="counter" select="6+$counter"/>
			</xsl:call-template>
		</xsl:when>
		<xsl:otherwise>
		</xsl:otherwise>
	</xsl:choose>
	</xsl:for-each>
</xsl:template>

<xsl:template name="blf">
 <xsl:param name="text"/>
 <xsl:choose>
   <xsl:when test="contains($text,'&#10;')">
     <xsl:value-of select="substring-before($text,'&#10;')"/>
   </xsl:when>
   <xsl:otherwise>
     <xsl:value-of select="$text"/>
   </xsl:otherwise>
 </xsl:choose>
</xsl:template>

<xsl:template name="lf2br">
 <xsl:param name="text"/>
 <xsl:choose>
   <xsl:when test="contains($text,'&#10;')">
     <xsl:value-of select="substring-before($text,'&#10;')"/>
     <br/>
     <xsl:call-template name="lf2br">
       <xsl:with-param name="text">
         <xsl:value-of select="substring-after($text,'&#10;')"/>
       </xsl:with-param>
     </xsl:call-template>
   </xsl:when>
   <xsl:otherwise>
     <xsl:value-of select="$text"/>
   </xsl:otherwise>
 </xsl:choose>
</xsl:template>

<xsl:template name="sp2br">
 <xsl:param name="text"/>
 <xsl:choose>
   <xsl:when test="contains($text,'&#32;')">
     <xsl:value-of select="substring-before($text,'&#32;')"/>
     <br/>
     <xsl:call-template name="sp2br">
       <xsl:with-param name="text">
         <xsl:value-of select="substring-after($text,'&#32;')"/>
       </xsl:with-param>
     </xsl:call-template>
   </xsl:when>
   <xsl:otherwise>
     <xsl:value-of select="$text"/>
   </xsl:otherwise>
 </xsl:choose>
</xsl:template>

<xsl:template name="produce-steps-list">
	<xsl:param name="count"/>
	<xsl:if test="$count != 0 ">
		<xsl:choose>
			<xsl:when test='not( @MyFirst=-1 and $count=(@nrsteps + 1)) and @MyFirst!=( @maxfirst - ( (  @nrsteps  - $count + 1) * @step ) )'>
				<a class="body_10px_red" href="{@MyUrl}?forumid={@ID}&amp;forumFirst={@maxfirst - ( (  @nrsteps  - $count + 1) * @step )}&amp;forumStep={@step}"><xsl:value-of select="$count"/></a>&#160;
			</xsl:when>
			<xsl:otherwise>
				<font class="fakeA"><xsl:value-of select="$count"/></font>&#160;
			</xsl:otherwise>
		</xsl:choose>
		<xsl:call-template name="produce-steps-list">
			<xsl:with-param name="count" select="$count - 1"/>
		</xsl:call-template>
	</xsl:if>
</xsl:template>

<xsl:template match="forum">

<table bgcolor="#EEEEEE" class="body" border="0" cellspacing="0" cellpadding="5" width="100%">
<tr>
<td colspan="3">
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
	<tr>
	<td width="75%" align="center">Forum: <xsl:value-of select="@title"/></td>
	<td width="25%" valign="middle">
	<xsl:choose>
		<xsl:when test='/forum/@logged'>
			<nobr><a class="body_10px_red" href="/post2forum.aspx?forum_id={@ID}"><img border="0" src="/imgs/mail.gif"/> Scrivi un messaggio</a></nobr>
		</xsl:when>
		<xsl:otherwise>
			<span class="body_10px_red" style="cursor:pointer; text-decoration: underline;" onmouseover="ShowTooltipRight('1scrivi');" onmouseout="HideTooltip('1scrivi');"><nobr><img src="/imgs/mail.gif"/> Scrivi un messaggio</nobr></span>
		</xsl:otherwise>
	</xsl:choose>
	</td>
	</tr>
	</table>
</td>
</tr>
<tr class="body_red">
<td>Utente</td>
<td>Messaggio</td>
<td>Inviato</td>
</tr>
<tr><td colspan="3" background="/imgs/dottedline.gif" width="100%" align="center"></td></tr>
<xsl:for-each select="message">
	<tr>
	<xsl:choose>
		<xsl:when test='@ngId'>
			<td class="body9">
			<xsl:value-of select="@ngFrom"/>
			</td>
		</xsl:when>
		<xsl:otherwise>
			<td class="body9"><a style="color:#006699;" href="/profileShow.aspx?userGuid={@userid}"><xsl:value-of select="@nick"/></a></td>
		</xsl:otherwise>
	</xsl:choose>
	<td>
	<a href="/forumReadMessage.aspx?forumid={/forum/@ID}&amp;msgid={@ID}">
	<img border="0" src="/imgs/message.gif"/>
	</a>
	&#160;
	<xsl:choose>
		<xsl:when test='@ngId'>
			<a href="/forumReadMessage.aspx?forumid={/forum/@ID}&amp;msgid={@ID}">
			<xsl:value-of select="@ngSubj"/>
			</a>
		</xsl:when>
		<xsl:otherwise>
			<xsl:choose>
				<xsl:when test='@textLen&gt;@maxLen'>
					<a href="/forumReadMessage.aspx?forumid={/forum/@ID}&amp;msgid={@ID}">
				  <xsl:call-template name="lf2br">
					<xsl:with-param name="text" select="@text"/>
				  </xsl:call-template>
					</a>
				</xsl:when>
				<xsl:otherwise>
				  <xsl:call-template name="lf2br">
					<xsl:with-param name="text" select="@text"/>
				  </xsl:call-template>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:otherwise>
	</xsl:choose>
	</td>
	<td class="body9">
		<xsl:call-template name="sp2br">
		<xsl:with-param name="text" select="@time"/>
		</xsl:call-template>
	</td>
	</tr>

<xsl:call-template name="subMessages">
<xsl:with-param name="messageID" select="@ID"/>
<xsl:with-param name="counter" select="4"/>
</xsl:call-template>

<tr><td colspan="3" background="/imgs/dottedline.gif" width="100%" align="center"></td></tr>

</xsl:for-each>
<tr><td colspan="3" align="center">
	<table border="0" width="100%"  cellpadding="0">
	<tr>
<xsl:choose>
	<xsl:when test='/forum/@logged'>
		<td align="left"><a class="body_10px_red" href="/post2forum.aspx?forum_id={@ID}">Scrivi un messaggio nel forum</a></td>
	</xsl:when>
	<xsl:otherwise>
		<td align="left"><font class="body_10px_red" style="cursor:pointer; text-decoration: underline;" onmouseover="ShowTooltipRight('1scrivi');" onmouseout="HideTooltip('1scrivi');">Scrivi un messaggio nel forum</font></td>
	</xsl:otherwise>
</xsl:choose>

	<td align="right">
<xsl:choose>
	<xsl:when test='@maxfirst!=@first'>
		<a class="body_10px_red" href="{@MyUrl}?forumid={@ID}&amp;forumFirst={@prevfirst}&amp;forumStep={@step}">prev</a>
	</xsl:when>
	<xsl:otherwise>
		<font class="fakeA" onmouseover="ShowTooltipRight('1prev');" onmouseout="HideTooltip('1prev');">prev</font>
	</xsl:otherwise>
</xsl:choose>
&#160;
<xsl:if test='@nrsteps&gt;0'>
		<xsl:call-template name="produce-steps-list">
			<xsl:with-param name="count" 		select="@nrsteps + 1"/>
		</xsl:call-template>
</xsl:if>
<xsl:choose>
	<xsl:when test='@nextfirst&gt;0'>
		<a class="body_10px_red" href="{@MyUrl}?forumid={@ID}&amp;forumFirst={@nextfirst}&amp;forumStep={@step}">next</a>
	</xsl:when>
	<xsl:otherwise>
		<font class="fakeA" onmouseover="ShowTooltipRight('1next');" onmouseout="HideTooltip('1next');">next</font>
	</xsl:otherwise>
</xsl:choose>
	</td>
	</tr>
	</table>
</td></tr>

</table>
<DIV CLASS="reminderTooltip" style="width:165;" ID='tt1scrivi'>
Guarda che se non ci dici chi sei non puoi scrivere un bel forum di niente! Dai, loggati o registrati.....
</DIV>
<DIV CLASS="reminderTooltip" style="width:165;" ID='tt1next'>
Non ci sono altri messaggi dopo.
</DIV>
<DIV CLASS="reminderTooltip" style="width:165;" ID='tt1prev'>
Non ci sono altri messaggi prima.
</DIV>
</xsl:template>

</xsl:stylesheet>